package com.smart.springaiopen.controller;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Guoxinyu
 * @description: TODO
 * @date 2025/5/28 11:12
 * @email gxy06x@qq.com
 */
@RestController
public class ChatModelController {

    @Autowired
    private ChatModel chatModel;

    @GetMapping("/chatModel01")
    public String chatModel(@RequestParam String msg) {
        return chatModel.call(msg);
    }
    @GetMapping("/chatMode02")
    public String chatModelStream(@RequestParam(value = "msg", defaultValue = "hello") String msg) {
        ChatResponse chatResponse = chatModel.call(new Prompt(
                msg,
                OpenAiChatOptions.builder()
                        .model("deepseek-chat")
                        .temperature(0.8)
                        .build()));
        return chatResponse.getResult().getOutput().getText();
    }
}
